﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.Web.GoodsDescription
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    Guid GoodsID = new Guid(Request.Params["id"]);
                    ShowInfo(GoodsID);
                }
            }
        }

        private void ShowInfo(Guid GoodsID)
        {
            Things.BLL.GoodsDescription bll = new Things.BLL.GoodsDescription();
            Things.Model.GoodsDescription model = bll.GetModel(GoodsID);
            this.lblGoodsID.Text = model.GoodsID.ToString();
            this.CKEditorControl1.Text = model.GoodsDescriptions;
            //this.Literal1.Text = model.GoodsDescriptions;
            Things.BLL.Goods goodsBLL = new BLL.Goods();
            Things.Model.Goods goods = goodsBLL.GetModel(model.GoodsID);
            this.lblGoodsName.Text = goods!=null?goods.GoodsName:string.Empty;
        }



        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            Guid GoodsID = Guid.Empty;
            if (Guid.TryParse(this.lblGoodsID.Text, out GoodsID) == false)
            {
                strErr += "商品信息有误！";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            
            string GoodsDescriptions = this.CKEditorControl1.Text;

            Things.BLL.GoodsDescription bll = new Things.BLL.GoodsDescription();
            Things.Model.GoodsDescription model = bll.GetModel(GoodsID);
            if (model != null)
            {
                model.GoodsDescriptions = GoodsDescriptions;

                bll.Update(model);
                Things.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
